`
https://leetcode.cn/problems/number-of-perfect-pairs/
`

/**
 * @param {number[]} nums
 * @return {number}
 */
var perfectPairs = function (nums) {
  // 思路：https://leetcode.cn/problems/number-of-perfect-pairs/solutions/3755121/yong-jue-dui-zhi-de-ji-he-yi-yi-hua-jian-xois/
  nums = nums.map((num) => Math.abs(num)).sort((a, b) => a - b)
  let res = 0
  let left = 0, right = 0

  while (right < nums.length) {
    const b = nums[right]
    while (nums[left] * 2 < b) {
      left++
    }
    res += right - left
    right++
  }

  return res
};